# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gd

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
pkgrel=2
pkgdesc='Library for the dynamic creation of images by programmers (mingw-w64)'
url='http://www.libgd.org/'
arch=('any')
license=("CPL")
options=(!libtool strip staticlibs)
depends=(
    "${MINGW_PACKAGE_PREFIX}-fontconfig"
    "${MINGW_PACKAGE_PREFIX}-libiconv"
    "${MINGW_PACKAGE_PREFIX}-libjpeg"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-libtiff"
    "${MINGW_PACKAGE_PREFIX}-libvpx"
    "${MINGW_PACKAGE_PREFIX}-xpm-nox"
    )
optdepends=('perl: bdftogd script')
source=("https://bitbucket.org/libgd/gd-libgd/downloads/libgd-${pkgver}.tar.xz")
md5sums=('03588159bf4faab9079849c8d709acc6')

prepare() {
  cd ${srcdir}/libgd-${pkgver}
}

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../libgd-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-static \
    --enable-shared \
    LIBXPM_CFLAGS="-I${MINGW_PREFIX}/include/noX" \
    LIBXPM_LIBS="-L${MINGW_PREFIX}/lib -lXpm"
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
